package paginas;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.WindowFocusListener;
import java.util.ResourceBundle;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;

import modelUtil.Util;
import usuario.usuarioTO.UsuarioTO;
import util.BotonPersonalizado;
import util.TransicionBotones;
import AccionBoton.AccionCerrar;
import AccionBoton.AccionFocoCreditos;
import AccionBoton.AccionFocoVentana;
import AccionBoton.AccionGuardarConfiguracionIntic;
import AccionBoton.AccionLanzarAyuda;

public class PaginaMenuConfig extends JDialog{


	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JTabbedPane _panel;
	private JPanel botones;
	private JPanel tab3;
	private JPanel tab1;
	private JPanel tab2;
	private UsuarioTO _user;
	private PaginaMenuAdmin _frame;
	private TransicionBotones policy;
	private BotonPersonalizado boton1, boton2, boton3;
	private Vector<Component> order;
	private WindowFocusListener foco;
	
	public PaginaMenuConfig(UsuarioTO user, PaginaMenuAdmin frame){
		
		_user =user;
		_frame = frame;
		initComponents();
        order = new Vector<Component>(6);
        order.add(tab1);
        order.add(tab2);
        order.add(tab3);
        order.add(boton1);
        order.add(boton2);
        order.add(boton3);

        foco = new AccionFocoVentana(tab1);

        _frame.get_contenedor().addWindowFocusListener(foco);
        _frame.get_contenedor().setFocusable(true);
       policy = new TransicionBotones(order);
       _frame.get_contenedor().setFocusTraversalPolicy(policy);
		this.setBounds(0, 0, 500, 550);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
	}
	
	
	private void initComponents(){
		
		GridBagLayout grid = new GridBagLayout();
		GridBagConstraints cons = new GridBagConstraints();
		
		cons.gridwidth = 1;
		cons.gridheight = 1;
		cons.fill = GridBagConstraints.BOTH;
		this.setLayout(grid);
		cons.gridx=0;
		cons.gridy = 0;
		_panel = new JTabbedPane();
		_panel.setPreferredSize(new Dimension(450,450));
		botones = new JPanel();

		grid.addLayoutComponent(_panel, cons);
		this.add(_panel);
		tab1 = new MenuConfigPasswordTab(_user);
		tab2 = new MenuConfigIdiomaTab();
		tab3 = new MenuConfigBarridoTab();

		
		_panel.addTab(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_menu_config_titulo_tab1"), tab1);
		_panel.addTab(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_menu_config_titulo_tab2"), tab2);
		_panel.addTab(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_menu_config_titulo_tab3"), tab3);

		
		boton1 = Util.BotonImagen(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_popup_admin_ayuda"),"lib//help.png");
		boton1.setMnemonic(KeyEvent.VK_Y);
		boton1.getLabelTexto().setDisplayedMnemonic(KeyEvent.VK_Y);
		boton1.addActionListener(new AccionLanzarAyuda(_frame.get_contenedor()));
		boton1.getLabelTexto().getAccessibleContext().setAccessibleName(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_menu_ayuda"));
		boton1.setToolTipText(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_menu_ayuda"));

		int alto = boton1.getLabelImagen().getIcon().getIconHeight();
		int ancho = boton1.getLabelImagen().getIcon().getIconWidth();

		double factorEscala = (double)(alto /  32);

		ancho = ((int) (ancho / factorEscala));
		alto = ((int) (alto / factorEscala));
		ImageIcon imagen = new ImageIcon("lib//help.png");
		Image redimensionada = imagen.getImage().getScaledInstance(ancho, alto, Image.SCALE_DEFAULT);
		boton1.getLabelImagen().setIcon(new ImageIcon(redimensionada));
		boton1.addFocusListener(new AccionFocoCreditos(boton1));
		boton1.getLabelTexto().setHorizontalAlignment(SwingConstants.RIGHT);
		boton1.getLabelImagen().setHorizontalAlignment(SwingConstants.LEFT);
		boton1.setPreferredSize(new Dimension(100,40));
		boton1.setBackground(new Color(238, 238, 238));
		
		boton2 = Util.BotonImagen(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_popup_admin_aceptar"),"lib//Aceptar.png");
		boton2.setMnemonic(KeyEvent.VK_A);
		boton2.addFocusListener(new AccionFocoCreditos(boton2));

		boton2.getLabelTexto().setDisplayedMnemonic(KeyEvent.VK_A);
		boton2.getLabelTexto().getAccessibleContext().setAccessibleName(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_config_intic_aceptar"));
		boton2.setToolTipText(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_config_intic_aceptar"));

		boton2.setPreferredSize(new Dimension(100,40));
		boton2.getLabelTexto().setHorizontalAlignment(SwingConstants.RIGHT);
		boton2.getLabelImagen().setHorizontalAlignment(SwingConstants.LEFT);
    	boton2.setBackground(new Color(238, 238, 238));
		boton2.addActionListener(new AccionGuardarConfiguracionIntic(_panel,_frame.get_contenedor()));
		
		boton3 = Util.BotonImagen(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_popup_admin_cancelar"),"lib//cancelar.png");
		boton3.setMnemonic(KeyEvent.VK_C);
		boton3.getLabelTexto().setDisplayedMnemonic(KeyEvent.VK_C);
		boton3.addFocusListener(new AccionFocoCreditos(boton3));

		boton3.getLabelTexto().getAccessibleContext().setAccessibleName(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_config_intic_cancelar"));
		boton3.setToolTipText(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_config_intic_cancelar"));

		boton3.setPreferredSize(new Dimension(100,40));
		boton3.getLabelTexto().setHorizontalAlignment(SwingConstants.RIGHT);
		boton3.getLabelImagen().setHorizontalAlignment(SwingConstants.LEFT);

		boton3.setBackground(new Color(238, 238, 238));
		boton3.addActionListener(new AccionCerrar(this,_frame));

		FlowLayout flow = new FlowLayout();
		botones.setPreferredSize(new Dimension(450,50));
		botones.setLayout(flow);
		flow.addLayoutComponent("boton1", boton1);
		botones.add(boton1);
		flow.addLayoutComponent("boton2", boton2);

		botones.add(boton2);
		flow.addLayoutComponent("boton3", boton3);

		botones.add(boton3);
		cons.gridx=0;
		cons.gridy=1;
		grid.addLayoutComponent(botones, cons);
		this.add(botones);
		
		
		
	}
	

	public JPanel getTab1() {
		return tab1;
	}


	public void setTab1(JPanel tab1) {
		this.tab1 = tab1;
	}


	public TransicionBotones getPolicy() {
		return policy;
	}


	public void setPolicy(TransicionBotones policy) {
		this.policy = policy;
	}


	public WindowFocusListener getFoco() {
		return foco;
	}


	public void setFoco(WindowFocusListener foco) {
		this.foco = foco;
	}
	
}
